package com.akuhome.resource.controller;

import com.akuhome.resource.dto.Form;
import com.akuhome.resource.entity.Project;
import com.akuhome.resource.service.entity.ProjectService;
import com.akuhome.resource.service.entity.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    ProjectService projectService;
    @Autowired
    UserService userService;
    @GetMapping
    public Object findAll(Integer userId){
        if(userId == null){
            return projectService.findAll();
        }else{
            return projectService.findAllByUserId(userId);
        }
    }

    @GetMapping("/my")
    public Object findAllByCurUserId(){
        return projectService.findAllByUserId(userService.getCurrentUserId());
    }

    @PostMapping(produces = "application/json;charset=UTF-8")
    public Object insert(@Validated @RequestBody Form form, BindingResult bindingResult){
        projectService.newProject(form);
        return null;
    }
    @PostMapping("/confirm/{pid}")
    public Object confirm(@PathVariable Integer pid){
        projectService.confirmProject(pid);
        return null;
    }

    @GetMapping("/init")
    public Project init(){
        return new Project();
    }

    @GetMapping("/accneed")
    public Object findAllProjectHaveAccNeed(){
        return projectService.findAllProjectHaveAccNeed();
    }

    @GetMapping("/foodneed")
    public Object findAllProjectHaveFoodNeed(){
        return projectService.findAllProjectHaveFoodNeed();
    }

    @GetMapping("/classroomneed")
    public Object findAllProjectHaveClassroomNeed(){
        return projectService.findAllProjectHaveClassroomNeed();
    }

    @GetMapping("/classroomneed/session")
    public Object findAllProjectHaveClassroomNeedSession(){
        return projectService.findAllProjectHaveClassroomNeedSession();
    }

    @GetMapping("/check/acc")
    public Object findAllProjectHaveAccCheck(){
        return projectService.findAllProjectHaveAccCheck();
    }

    @GetMapping("/check/food")
    public Object findAllProjectHaveFoodCheck(){
        return projectService.findAllProjectHaveFoodCheck();
    }
    @GetMapping("/check/classroom")
    public Object findAllProjectHaveClassroomCheck(){
        return projectService.findAllProjectHaveClassroomCheck();
    }
}
